import vue from '@vitejs/plugin-vue'
import { defineConfig, externalizeDepsPlugin } from 'electron-vite'
import { resolve } from 'path'
const publicDir = resolve('resources')
const envDir = resolve('build')
export default defineConfig({
  main: {
    plugins: [externalizeDepsPlugin()]
  },
  preload: {
    plugins: [externalizeDepsPlugin()]
  },
  renderer: {
    publicDir,
    envDir,
    envPrefix: 'RENDERER_',
    resolve: {
      alias: {
        '@renderer': resolve('src/renderer/src'),
        '@views': resolve('src/renderer/src/views'),
        '@router': resolve('src/renderer/src/router'),
        '@store': resolve('src/renderer/src/store'),
        '@utils': resolve('src/renderer/src/utils'),
        '@api': resolve('src/renderer/src/api'),
        '@config': resolve('src/renderer/src/config')
      }
    },
    // 开发服务器配置，配置代理，解决前后端的跨域问题
    server: {
      host: '0.0.0.0', // 服务器地址
      port: 5371,
      open: false, // 是否自动打开浏览器
      hmr: true, // 启用热更新
      proxy: {
        '/api': {
          target: 'http://127.0.0.1:9999',
          changeOrigin: true, // 是否修改请求头中的 Origin 字段
          // 重写路径，将请求路径中的 /api 替换为空
          rewrite: (path) => path.replace(/^\/api/, '')
        }
      }
    },
    plugins: [vue()]
  }
})
